From 05fbb602adedae84ca8771a36de50b15085d73a1 Mon Sep 17 00:00:00 2001 From: Xiaofeng Ling Date: Thu, 10 Nov 2005 17:07:13 +0100 Subject: [PATCH] This patch use same expression as vif for vmx guest but has a distinguish "type=ioemu" just like block device. e.g. vif=['type=ioemu, mac=01:00:00:00:00:33, bridge=xenbr0'] type=ioemu to specify for vmx NIC device. nics=4 can specify 4 vmx NIC now. bridge is passed to device model now. With this patch, the error "Error: Device 0 (vif) could not be connected." will not happen for creating vmx guest currently, it happens on some linux distribution. Signed-off-by: Xiaofeng Ling --- tools/examples/xmexample.vmx | 6 +++++- tools/ioemu/target-i386-dm/qemu-ifup | 2 +- tools/ioemu/vl.c | 10 +++++++++- tools/python/xen/xend/image.py | 11 +++++++++++ tools/python/xen/xend/server/netif.py | 3 +++ tools/python/xen/xm/create.py | 15 ++++++++------- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tools/examples/xmexample.vmx b/tools/examples/xmexample.vmx index 5b4ca9c5c8..e3d4d44ba9 100644 --- a/tools/examples/xmexample.vmx +++ b/tools/examples/xmexample.vmx @@ -35,7 +35,11 @@ vcpus=1 # Optionally define mac and/or bridge for the network interfaces. # Random MACs are assigned if not given. -#vif = [ 'mac=aa:00:00:00:00:11, bridge=xenbr0' ] +# nics default is 1 +#vif = [ 'type=ioemu, mac=aa:00:00:00:00:11, bridge=xenbr0' ] +nics=1 +# type=ioemu specify the NIC is an ioemu device not netfront +vif = [ 'type=ioemu, bridge=xenbr0' ] #---------------------------------------------------------------------------- # Define the disk devices you want the domain to have access to, and diff --git a/tools/ioemu/target-i386-dm/qemu-ifup b/tools/ioemu/target-i386-dm/qemu-ifup index a23f1d2b68..40d66b42d8 100755 --- a/tools/ioemu/target-i386-dm/qemu-ifup +++ b/tools/ioemu/target-i386-dm/qemu-ifup @@ -7,4 +7,4 @@ echo 'config qemu network with xen bridge for ' echo $* ifconfig $1 0.0.0.0 up -brctl addif xenbr0 $1 +brctl addif $2 $1 diff --git a/tools/ioemu/vl.c b/tools/ioemu/vl.c index 89b89fb5c2..b6fb5e923d 100644 --- a/tools/ioemu/vl.c +++ b/tools/ioemu/vl.c @@ -124,6 +124,7 @@ int domid = -1; static char network_script[1024]; int pit_min_timer_count = 0; int nb_nics; +char bridge[16]; NetDriverState nd_table[MAX_NICS]; QEMUTimer *gui_timer; QEMUTimer *polling_timer; @@ -1586,7 +1587,7 @@ static void tun_add_read_packet(NetDriverState *nd, static int net_tun_init(NetDriverState *nd) { int pid, status; - char *args[3]; + char *args[4]; char **parg; extern int highest_fds; @@ -1602,6 +1603,7 @@ static int net_tun_init(NetDriverState *nd) parg = args; *parg++ = network_script; *parg++ = nd->ifname; + *parg++ = bridge; *parg++ = NULL; execv(network_script, args); exit(1); @@ -2207,6 +2209,7 @@ void help(void) "Network options:\n" "-nics n simulate 'n' network cards [default=1]\n" "-macaddr addr set the mac address of the first interface\n" + "-bridge br set the bridge interface for nic\n" "-n script set tap/tun network init script [default=%s]\n" "-tun-fd fd use this fd as already opened tap/tun interface\n" #ifdef CONFIG_SLIRP @@ -2297,6 +2300,7 @@ enum { QEMU_OPTION_nics, QEMU_OPTION_macaddr, + QEMU_OPTION_bridge, QEMU_OPTION_n, QEMU_OPTION_tun_fd, QEMU_OPTION_user_net, @@ -2367,6 +2371,7 @@ const QEMUOption qemu_options[] = { { "nics", HAS_ARG, QEMU_OPTION_nics}, { "macaddr", HAS_ARG, QEMU_OPTION_macaddr}, + { "bridge", HAS_ARG, QEMU_OPTION_bridge}, { "n", HAS_ARG, QEMU_OPTION_n }, { "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd }, #ifdef CONFIG_SLIRP @@ -2825,6 +2830,9 @@ int main(int argc, char **argv) exit(1); } break; + case QEMU_OPTION_bridge: + pstrcpy(bridge, sizeof(bridge), optarg); + break; case QEMU_OPTION_macaddr: { const char *p; diff --git a/tools/python/xen/xend/image.py b/tools/python/xen/xend/image.py index 6f8231aac7..b4111d8768 100644 --- a/tools/python/xen/xend/image.py +++ b/tools/python/xen/xend/image.py @@ -258,6 +258,7 @@ class VmxImageHandler(ImageHandler): log.debug("args: %s, val: %s" % (a,v)) # Handle disk/network related options + mac = None for (name, info) in deviceConfig: if name == 'vbd': uname = sxp.child_value(info, 'uname') @@ -276,11 +277,21 @@ class VmxImageHandler(ImageHandler): ret.append("-%s" % vbddev) ret.append("%s" % vbdparam) if name == 'vif': + type = sxp.child_value(info, 'type') + if type != 'ioemu': + continue + if mac != None: + continue mac = sxp.child_value(info, 'mac') + bridge = sxp.child_value(info, 'bridge') if mac == None: mac = randomMAC() + if bridge == None: + bridge = 'xenbr0' ret.append("-macaddr") ret.append("%s" % mac) + ret.append("-bridge") + ret.append("%s" % bridge) if name == 'vtpm': instance = sxp.child_value(info, 'instance') ret.append("-instance") diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py index 782ccf0215..b4ea86de2c 100644 --- a/tools/python/xen/xend/server/netif.py +++ b/tools/python/xen/xend/server/netif.py @@ -71,6 +71,9 @@ class NetifController(DevController): script = os.path.join(xroot.network_script_dir, sxp.child_value(config, 'script', xroot.get_vif_script())) + type = sxp.child_value(config, 'type') + if type == 'ioemu': + return (None,{},{}) bridge = sxp.child_value(config, 'bridge') mac = sxp.child_value(config, 'mac') ipaddr = _get_config_ipaddr(config) diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index 4956cc360e..af7080fd56 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -255,10 +255,11 @@ gopts.var('ipaddr', val="IPADDR", fn=append_value, default=[], use="Add an IP address to the domain.") -gopts.var('vif', val="mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME", +gopts.var('vif', val="type=TYPE,mac=MAC,be_mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME", fn=append_value, default=[], use="""Add a network interface with the given MAC address and bridge. The vif is configured by calling the given configuration script. + If type is not specified, default is netfront not ioemu device. If mac is not specified a random MAC address is used. The MAC address of the backend interface can be selected with be_mac. If not specified then the network backend chooses it's own MAC address. @@ -356,10 +357,6 @@ gopts.var('cdrom', val='FILE', fn=set_value, default='', use="Path to cdrom") -gopts.var('macaddr', val='MACADDR', - fn=set_value, default='', - use="Macaddress of the first network interface") - gopts.var('boot', val="a|b|c|d", fn=set_value, default='c', use="Default boot device") @@ -512,6 +509,7 @@ def configure_vifs(config_devs, vals): backend = d.get('backend') ip = d.get('ip') vifname = d.get('vifname') + type = d.get('type') else: mac = None be_mac = None @@ -520,6 +518,7 @@ def configure_vifs(config_devs, vals): backend = None ip = None vifname = None + type = None config_vif = ['vif'] if mac: config_vif.append(['mac', mac]) @@ -535,6 +534,8 @@ def configure_vifs(config_devs, vals): config_vif.append(['backend', backend]) if ip: config_vif.append(['ip', ip]) + if type: + config_vif.append(['type', type]) config_devs.append(['device', config_vif]) def configure_vfr(config, vals): @@ -549,7 +550,7 @@ def configure_vmx(config_image, vals): """Create the config for VMX devices. """ args = [ 'device_model', 'vcpus', 'cdrom', 'boot', 'fda', 'fdb', - 'localtime', 'serial', 'macaddr', 'stdvga', 'isa', 'nographic', + 'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display', 'ne2000', 'lapic'] for a in args: if (vals.__dict__[a]): @@ -662,7 +663,7 @@ def preprocess_vifs(vals): (k, v) = b.strip().split('=', 1) k = k.strip() v = v.strip() - if k not in ['mac', 'be_mac', 'bridge', 'script', 'backend', 'ip', 'vifname']: + if k not in ['type', 'mac', 'be_mac', 'bridge', 'script', 'backend', 'ip', 'vifname']: err('Invalid vif specifier: ' + vif) d[k] = v vifs.append(d) -- 2.30.2